﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    class Student
    {
        public string Name { get; set; }
        public string Course { get; set; }
        public int Score { get; set; }
        public int Age { get; set; }
        public string College { get; set; }
    }
    class Program
    {
        public delegate bool Opera(int num);
        public static bool CheckAge(int age)
        {
            return age >= 18 & age <= 24;
        }
        static void Main(string[] args)
        {
            //创建学生列表，并完成8行数据的初始化工作  模拟数据
            List<Student> names = new List<Student>
           {
               new Student (){Name="马保国",College="",Course="闪电五连鞭",Score=80,Age=69},
               new Student (){Name="混元形意太极掌门人",College="",Course="左正蹬",Score=70,Age=69},
               new Student (){Name="200斤的英国大力士",College="",Course="偷袭",Score=60,Age=30},
               new Student (){Name="希望你们",College="",Course="耗子尾汁",Score=50,Age=66},
               new Student (){Name="我大意了",College="",Course="没有闪",Score=40,Age=69},
               new Student (){Name="小伙子",College="",Course="不讲武德",Score=30,Age=30},
               new Student (){Name="69岁的老同志",College="",Course="右鞭腿",Score=20,Age=69},
               new Student (){Name="年轻人",College="",Course="左刺拳",Score=10,Age=30}
           };
            ///from、where 、selecr ——预定义
            ///LINQ查询表达式必须以from开头，以select或group子句结束
            ///中间的子句是where、orderby等子句
            ///

            //子查询
            var query1 = from Student in names
                        where Student.College.Equals("财经学院")
                        group Student by Student.Course
                        into cjCourse
                        select new
                        {
                            key = cjCourse.Key,
                            maxAge = cjCourse.Max(x => x.Age)
                        };
            foreach (var item in names)
            {
                Console.WriteLine($"{item.Name},{item.Course},{item.College}");
            }
            //链接查询——join
            //List<Course> course = new List<Course>()
            //{
            //    new Course(){IDictionary=1,Name="大学英语"}
            //};
            //var courseLINQ = from c in names
            //                 join c1 in course on c.Course equals c1.Name
            //                 select new
            //                 {
            //                     course = c1.Name
            //                 };

            //合并——zip
            var list1 = from a in names
                        where a.Age < 18
                        select a;
            var list2 = from a in names
                        where a.Age > 24
                        select a;
            var resultList = list1.Zip(list2, (L1, L2)=>L1.Name + L2.Name);

            //分页查询实现：Take()Skip()配合完成区分操作
            int pageSize = 4;//每页显示的数据行数
            int pageIndex = 0;//当前页码
            var pageList = (from p in names
                            select p)
                          .Skip(pageIndex * pageSize)//Skip()--跳过的数据行数
                          .Take(pageSize);//提取的数据行数
            Console.WriteLine("第一页数据：");
            foreach (var item in pageList)
            {
                Console.WriteLine($"{item}");
            }
            //LINQ转XML，LINQ转Json
            //LINQ分布式编程(高并发编程实现)
            //表达式树

            ///Lambda和Linq
            ///Lambda基于方法的Linq查询，标准查询运算方法——语法
            ///Lambda是表达式(委托匿名函数的一种实现，实现比较见简单)，Linq是查询语句
            ///Lambda采用符号链接(点链式)，Linq采用语句实现
            ///Linq是Lambda的实现
            ///
            ///线程Thread
            ///任务Task
            ///async、awaot


            //异步实现原理(Thread)
            ///异步方法实现，引入任务(Task)
            ///异步应用
            ///前端：Bootstrap(登录、导航、轮播、列表内容)——项目评分初评
            ///
            ///Js(变量值变化、BOM、DOM、函数)
            ///jQuery(DOM、和事件)
            ///10月28——其中测试(机试和口试)

            Console.WriteLine();
            Console.ReadKey();
        }
        public void Example()
        {
            ////查找财经学院的学生数据，并按年龄降序、姓名升序排序
            //var query = from Student in names //引入数据源names，Student——names数据源的范围变量
            //            where Student.College == "财经学院"
            //            orderby Student.Age descending
            //            orderby Student.Name
            //            select Student;
            //foreach (var item in query)
            //{
            //    Console.WriteLine($"{item.Name },{item.Age},{item.College}");
            //}

            ////采用以往的一般方式实现年龄18~24岁的学生数据
            //foreach (var item in names)
            //{
            //    if (item.Age >= 18 && item.Age <= 24)
            //    {
            //        Console.WriteLine($"");
            //    }
            //}
            ////采用委托方式实现年龄18~24岁的学生数据
            //Opera op = CheckAge;
            //foreach (var item in names)
            //{
            //    if (op(item.Age))
            //    {
            //        Console.WriteLine($"{item}");
            //    }
            //}
            ////采用Linq方式实现年龄18~24岁的学生数据
            //var chkAgeLambda = names.Where(x => x.Age >= 18 && x.Age <= 24).ToList();
            //var chkAgeLINQ = from a in names
            //                 where a.Age >= 18 && a.Age <= 24
            //                 select a;




            ////linq实现查找课程--select Course from list group by Course
            //var query = from X in names
            //            group X by X.Course;
            //foreach (var item in query)
            //{
            //    Console.WriteLine($"{item.Key}");
            //}
            ////linq实现查找60分以上的学生数据
            //var query2 = from Student in names
            //             where Student.Score > 60
            //             select Student;
            //foreach (var item in query2)
            //{
            //    Console.WriteLine($"成绩在60分以上的所有{item.Name }");
            //}

            ////linq实现按成绩降序排列
            //var query3 = from j in names
            //             orderby j.Score descending
            //             select j;
            //foreach (var item in query3)
            //{
            //    Console.WriteLine($"成绩按降序排序后{item.Score}");
            //}
        }
    }
}
